Page({
  data: {
    // videoUrl: 'https://vod4.buycar5.cn/20210304/Vzu3MO7B/index.m3u8'
    videoUrl: '',
    vod_pic: '',
    vod_name: '',
    type_name: '',
    vod_douban_score: '0.0',
    vod_tag:'',
    vod_year:'',
    vod_writer:'',
    vod_blurb:'',
    vod_actor:'',
    id: 0,
    list: [], //视频集数链接列表
    active: 0 //当前播放第几集下标
  },
  onLoad(options) {
    this.setData({
      id: options.id
    })
    this.getVideoDetail()
  },
  onShow() {

  },

  // 转换数据
  replaceData(str) {
    // let str = '第1话$https://vod2.buycar5.cn/20200928/pvJswIZH/index.m3u8#第2集$https://vod2.buycar5.cn/20201011/yp1BV6HB/index.m3u8#第3集$https://vod2.buycar5.cn/20201018/5XXa6aK3/index.m3u8#第4集$https://vod2.buycar5.cn/20201025/lN3hA88b/index.m3u8#第5集$https://vod2.buycar5.cn/20201101/WdZmle2N/index.m3u8#第6集$https://vod3.buycar5.cn/20201108/k9nCHKeA/index.m3u8#第7集$https://vod3.buycar5.cn/20201114/7j9vzO3s/index.m3u8#第08集$https://vod3.buycar5.cn/20201121/5BksblHb/index.m3u8#第09集$https://vod3.buycar5.cn/20201128/fNXMeq7X/index.m3u8#第10集$https://vod5.wenshibaowenbei.com/20201205/YwpkycPq/index.m3u8#第11集$https://vod3.buycar5.cn/20201212/KCFzpSzm/index.m3u8#第12集$https://vod3.buycar5.cn/20201219/EhOl3bp8/index.m3u8#第13集$https://vod3.buycar5.cn/20201226/c7EIpG3E/index.m3u8#第14集$https://vod3.buycar5.cn/20210116/P0cbehnd/index.m3u8#第15集$https://vod3.buycar5.cn/20210123/F45SLTFX/index.m3u8#第16集$https://vod3.buycar5.cn/20210130/a0lCJ29B/index.m3u8#第17集$https://vod3.buycar5.cn/20210206/lKgYdOr3/index.m3u8#第18集$https://vod3.buycar5.cn/20210220/KYPyANtr/index.m3u8#第19集$https://vod3.buycar5.cn/20210220/qIsum4sW/index.m3u8#第20集$https://vod3.buycar5.cn/20210227/u1XQOFqj/index.m3u8#第21集$https://vod3.buycar5.cn/20210306/ZSm3Kuq2/index.m3u8'
    var list = str.match(/\http.*?\m3u8/g) //  \s 会被识别成正则表达式   要进行转义
    // console.log(list)
    this.setData({
      list,
      videoUrl: list[0]
    })
  },
  // 切换集数
  onChangeNumber(e) {
    // console.log('e',e.currentTarget.dataset.index)
    let active = e.currentTarget.dataset.index
    this.setData({
      active,
      videoUrl:this.data.list[e.currentTarget.dataset.index]
    })
  },
  onShareAppMessage() {
    return {
      title: 'video',
      path: 'page/component/pages/video/video'
    }
  },

  onReady() {
    this.videoContext = wx.createVideoContext('myVideo')
  },

  onHide() {

  },

  videoErrorCallback(e) {
    // console.log('视频错误信息:')
    // console.log(e.detail.errMsg)
  },
  // 获取数据
  getVideoDetail() {
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: `https://m3u8.apibdzy.com/api.php/provide/vod/?ac=detail&ids=${this.data.id}`, //仅为示例，并非真实的接口地址
      success: (res) => {
        // console.log(res.data.list[0])
        this.replaceData(res.data.list[0].vod_play_url)
        let vod_pic = res.data.list[0].vod_pic
        let vod_name = res.data.list[0].vod_name
        let type_name = res.data.list[0].type_name
        let vod_douban_score = res.data.list[0].vod_douban_score
        let vod_tag = res.data.list[0].vod_tag
        let vod_year = res.data.list[0].vod_year
        let vod_writer = res.data.list[0].vod_writer
        let vod_blurb = res.data.list[0].vod_blurb
        let vod_actor = res.data.list[0].vod_actor
        this.setData({
          vod_pic,
          vod_name,
          type_name,
          vod_douban_score,
          vod_tag,
          vod_year,
          vod_writer,
          vod_blurb,
          vod_actor
        })
      },
      fail: (err) => {

      },
      complete: () => {
        wx.hideLoading()
      }
    })
  }
})